<!-- 楼层 -->
<template>
    <div class="floorDetail">
        <div class="topDetail">
            <div class="topDetailOne">
                <div class="selectValue">
                    <label class="value">
                        <span class="img">
                            <img src="../../../assets/images/airIndex/qst.png" />
                        </span>
                        <span class="title">趋势图</span>
                        <span style="margin-left: 10px">
                            <DatePicker
                                :type="getDateType()"
                                placeholder="请选择"
                                :value="dateValue"
                                @on-change="changeDate"
                                style="width: 120px; margin-right: 10px"
                            ></DatePicker>

                            <el-button-group>
                                <el-button
                                    :type="currentEcharts == 'month' ? 'primary' : 'default'"
                                    size="mini"
                                    @click="echartBtnClick('month')"
                                    >当月</el-button
                                >
                                <el-button
                                    :type="currentEcharts == 'year' ? 'primary' : 'default'"
                                    size="mini"
                                    @click="echartBtnClick('year')"
                                    >当年</el-button
                                >
                            </el-button-group>
                        </span>
                    </label>
                    <div class="rightValue">
                        <div class="btnList">
                            <el-tooltip content="用电趋势" placement="left">
                                <img
                                    src="../../../assets/images/1103/用电趋势.svg"
                                    style="margin-right: 10px; cursor: pointer; margin-top: 16px"
                                    :class="phIndex == 1 ? 'qsHover' : ''"
                                    @click="changePh(1)"
                                />
                            </el-tooltip>
                            <el-tooltip content="用水趋势" placement="left">
                                <img
                                    src="../../../assets/images/1103/用水趋势.svg"
                                    :class="phIndex == 2 ? 'qsHover' : ''"
                                    style="cursor: pointer"
                                    @click="changePh(2)"
                            /></el-tooltip>
                        </div>
                    </div>
                </div>
                <div class="floor-left-top-table">
                    <deviceLeftEcharts
                        :name="phIndex"
                        :key="phIndex"
                        :currentNodeId="currentNodeId"
                        :currentNodeName="currentNodeName"
                        :dir="dir"
                        :eqtype="phIndex == 1 ? '01' : '02'"
                        :date="dateValue"
                        :currentEcharts="currentEcharts"
                    ></deviceLeftEcharts>
                </div>
            </div>
            <div class="topDetailTwo">
                <div
                    class="floor-left-top-table"
                    style="height: 360px; margin-top: 0px !important; background-color: transparent; overflow: hidden"
                >
                    <div class="items">
                        <div class="itemsTitle">
                            <div class="itemsTitleLeft">
                                <img src="../../../assets/images/airIndex/nzydl.png" />
                                <label>年总用电量（{{ phIndex == 1 ? 'kWh' : 'm³' }}）</label>
                            </div>
                        </div>
                        <div class="itemsContent" style="padding-top: 20px">
                            <div class="itemsContentRightValueNoMoney">{{ nzydl }}</div>
                        </div>
                    </div>
                    <div class="items">
                        <div class="itemsTitle">
                            <div class="itemsTitleLeft">
                                <img src="../../../assets/images/airIndex/njfze.png" />
                                <label>年缴费总额（元）</label>
                            </div>
                        </div>
                        <div class="itemsContent">
                            <div class="itemsContentLeftValue red">&nbsp;</div>
                            <div class="itemsContentRightValue">{{ njfze }}</div>
                        </div>
                    </div>
                    <div class="items">
                        <div class="itemsTitle">
                            <div class="itemsTitleLeft">
                                <img src="../../../assets/images/airIndex/nbzze.png" />
                                <label>年补贴总额（元）</label>
                            </div>
                        </div>
                        <div class="itemsContent">
                            <div class="itemsContentLeftValue blue">&nbsp;</div>
                            <div class="itemsContentRightValue">{{ nbtze }}</div>
                        </div>
                    </div>
                    <div class="items">
                        <div class="itemsTitle">
                            <div class="itemsTitleLeft">
                                <img src="../../../assets/images/airIndex/qfze.png" />
                                <label>欠费总额（元）</label>
                            </div>
                        </div>
                        <div class="itemsContent">
                            <div class="itemsContentLeftValue blue">&nbsp;</div>
                            <div class="itemsContentRightValue">{{ qfze }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottomDetail">
            <div class="BottomThree">
                <div class="floor-left-bottom-table-item">
                    <deviceLeftPieZb :currentNodeId="currentNodeId" :currentNodeName="currentNodeName"></deviceLeftPieZb>
                </div>
            </div>
            <div class="BottomThree">
                <div class="floor-left-bottom-table-item">
                    <deviceLeftTableList :currentNodeId="currentNodeId" :currentNodeName="currentNodeName"></deviceLeftTableList>
                </div>
            </div>
            <div class="BottomThree">
                <div class="floor-left-bottom-table-item">
                    <deviceLeftTableSbList :currentNodeId="currentNodeId" :currentNodeName="currentNodeName"></deviceLeftTableSbList>
                </div>
            </div>
            <div class="BottomOne">
                <div class="floor-left-bottom-table">
                    <div class="floor-left-bottom-table-all">
                        <div class="selectValue" style="background-color: #f5f5f5; margin: 10px">
                            <label class="value">
                                <span class="img">
                                    <img src="@/assets/images/airIndex/warn.png" />
                                </span>
                                <span class="title">告警信息</span>
                            </label>
                        </div>

                        <div id="chart-container" style="padding: 0 10px 10px 10px; margin: 0 auto">
                            <el-table :data="dataList" style="width: 100%" size="small" border :height="getHeight1() + 'px'">
                                <el-table-column prop="name" label="告警类型">
                                    <template slot-scope="scope">
                                        <div class="alarm-type">
                                            <img :src="getImg(scope.row.name)" style="width: 15px; height: 15px" />
                                            <span>{{ scope.row.name }}</span>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="value" label="告警次数" align="right">
                                    <template slot-scope="scope">
                                        <label style="cursor: pointer">{{ scope.row.value }} <i class="el-icon-arrow-right"></i></label>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import moment from 'moment'
import deviceLeftEcharts from './deviceLeftEcharts.vue'
import deviceLeftPieZb from './deviceLeftPieZb'
import deviceLeftTableList from './deviceLeftTableList'
import deviceLeftTableSbList from './deviceLeftTableSbList'
import {AjaxCommon} from '@/libs/apiCommon'
import {PopupCommon} from '@/libs/popupCommon'
import {Utility} from '@/libs/utility.js'
export default {
    props: ['currentNodeId', 'currentNodeName', 'dir'],
    components: {
        deviceLeftEcharts,
        deviceLeftPieZb,
        deviceLeftTableList,
        deviceLeftTableSbList
    },
    watch: {
        currentNodeId: {
            handler(newV) {
                if (newV && newV != '1') {
                    this.getData()
                }
            },
            deep: true,
            immediate: true
        }
    },
    data() {
        return {
            dateValue: Utility.getCurrentTime(),
            currentEcharts: 'month',
            year: '2025',
            yearList: [
                {
                    label: '2025',
                    value: '2025'
                },
                {
                    label: '2024',
                    value: '2024'
                }
            ],
            phIndex: 1,
            radio2: '2024',
            dataList: [
                {id: 1, value: 0, name: '欠费告警'},
                {id: 2, value: 0, name: '欠费停电'},
                {id: 3, value: 0, name: '过载跳电'},
                {id: 4, value: 0, name: '恶性跳电'},
                // {id: 5, value: 0, name: '定时分闸'},
                // {id: 6, value: 9, name: '定时合闸'},
                {id: 7, value: 11, name: '仪表离线'},
                {id: 8, value: 11, name: '网关离线'}
            ],
            /** 年总用电量 */
            nzydl: 0,
            /** 年缴费总额 */
            njfze: 0,
            /** 年补贴总额 */
            nbtze: 0,
            /** 欠费总额 */
            qfze: 0
        }
    },
    computed: {},
    created() {},
    methods: {
        changeDate(e) {
            this.dateValue = e
            this.getData()
        },
        getDateType() {
            if (this.currentEcharts == 'month') {
                return 'month'
            }
            if (this.currentEcharts == 'year') {
                return 'year'
            }
        },
        echartBtnClick(btnName) {
            this.dateValue = Utility.getCurrentTime()
            this.currentEcharts = btnName
            this.getData()
        },
        getData() {
            const currentNodeId = this.currentNodeId
            const self = this
            const eqType = this.phIndex == 1 ? '01' : '02'

            let dateN = this.dateValue?.replaceAll('-', '/')

            const currentEcharts = this.currentEcharts
            this.curYear = dateN.substr(0, 4)
            this.curMonth = null
            if (currentEcharts == 'month') {
                dateN = dateN.substr(0, 7)
            } else {
                dateN = dateN.substr(0, 10)
            }

            // 年总用量传02
            AjaxCommon(`/api/Payment/GetSALE_PAYSUM?bd_guid=${currentNodeId}&eq_type=${eqType}&time=${dateN}`, 'get', null).then((res) => {
                if (res?.data?.Code == 200) {
                    // diff_value_sum 年总使用量 amount_sum年总使用金额 ac_sum 当前账户余额 pay_sum 年缴费金额 free_pay_sum 年补贴金额 ac_use_sum 年使用金额 overdue_sum 欠费金额
                    const data = res?.data.Message?.[0]

                    self.nzydl = data.diff_value_sum
                    self.nbtze = data.free_pay_sum
                    self.njfze = data.pay_sum
                    self.qfze = data.overdue_sum
                } else {
                    PopupCommon.notify('error', res?.data?.msg)
                }
            })
        },
        getHeight1() {
            if (document.body.clientWidth > 1910) {
                console.log(11)
                return document.body.clientHeight - 570
            } else if (document.body.clientWidth > 1400) {
                console.log(22)
                return 280
            }
        },
        getImg(name) {
            if (name == '欠费告警') {
                return require('@/assets/images/other/yszwcx.png')
            }
            if (name == '欠费停电') {
                return require('@/assets/images/other/qftd.png')
            }
            if (name == '过载跳电') {
                return require('@/assets/images/other/gztd.png')
            }
            if (name == '恶性跳电') {
                return require('@/assets/images/other/extd.png')
            }
            if (name == '定时分闸') {
                return require('@/assets/images/other/dsfz.png')
            }
            if (name == '定时合闸') {
                return require('@/assets/images/other/dsfz.png')
            }
            if (name == '仪表离线') {
                return require('@/assets/images/other/yblx.png')
            }
            if (name == '网关离线') {
                return require('@/assets/images/other/wglx.png')
            }
        },
        getTitle() {
            var title = ''
            if (this.phIndex == 1) {
                title = '电'
            }
            if (this.phIndex == 2) {
                title = '水'
            }
            if (this.phIndex == 3) {
                title = '气'
            }
            if (this.phIndex == 4) {
                title = '热'
            }
            return title
        },
        changePh(index) {
            this.phIndex = index
            this.getData()
        }
    }
}
</script>

<style scoped lang="scss">
.floorDetail {
    position: relative;
    background-color: #f5f5f5;
    display: flex;
    height: 100%;
    width: 100%;
    gap: 10px;
    flex-direction: column;
    overflow-y: auto;
    &::-webkit-scrollbar {
        width: 0px; // 滚动条宽度
        display: none;
    }

    // 宽度小于1500px
    @media screen and (max-width: 1400px) {
        .selectValue {
            margin-top: 0 !important;
        }
        .topDetail {
            gap: 10px;
            width: 100%;
            display: flex;
            flex-direction: column;
            .topDetailOne {
                width: 100%;
                height: 360px;
                background-color: #fff;
            }
            .topDetailTwo {
                width: 100%;
                height: 360px;
                background-color: #fff;
            }

            .bottomDetail {
                width: 100%;
                display: flex;
                gap: 10px;
                flex-wrap: wrap;
            }
            .BottomThree {
                height: 360px;
                width: calc((100% - 10px) / 2);
                background-color: #fff;
                display: flex;
                overflow: hidden;
            }
            .BottomOne {
                height: 360px;
                width: calc((100% - 10px) / 2);
                background-color: #fff;
                display: flex;
                overflow: hidden;
            }
        }
    }

    @media screen and (min-width: 1400px) {
        .topDetail {
            height: 360px;
            gap: 10px;
            width: 100%;
            display: flex;
            .topDetailOne {
                // flex: 1;
                width: calc(100% - 310px);
                height: 360px;
                background-color: #fff;
            }
            .topDetailTwo {
                width: 300px;
                height: 360px;
                background-color: #fff;
            }
        }

        .bottomDetail {
            width: 100%;
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }
        .BottomThree {
            height: 360px;
            width: calc((100% - 10px) / 2);
            background-color: #fff;
            display: flex;
            overflow: hidden;
        }
        .BottomOne {
            height: 360px;
            width: calc((100% - 10px) / 2);
            background-color: #fff;
            display: flex;
            overflow: hidden;
        }
    }

    @media screen and (min-width: 1800px) {
        .bottomDetail {
            height: calc(100vh - 494px);
            width: 100%;
            display: flex;
            gap: 10px;
        }
        .BottomThree {
            height: calc(100vh - 494px);
            width: calc((100% - 330px) / 3);
            background-color: #fff;
            display: flex;
        }
        .BottomOne {
            width: 300px;
            height: calc(100vh - 494px);
            background-color: #fff;
            display: flex;
        }
    }

    .floor-left-bottom-table-item {
        width: 100%;
        position: relative;
        height: 100%;
        cursor: pointer;
        background-color: #fff;
    }

    .floor-left-bottom-table-all {
        width: 100%;
        position: relative;
        height: 100%;
        cursor: pointer;
        background-color: #fff;
        .alarm-type {
            display: flex;
            align-items: center;
            gap: 10px;
        }
    }
    .floor-left-bottom-table {
        background-color: #f5f5f5;
        display: flex; /* flex布局 */
        justify-content: flex-start; /* 左对齐 */
        flex-wrap: wrap; /* 换行 */
        height: calc(100% - 370px);
        width: 100%;
    }

    .floor-left-top-table {
        height: 300px;
        margin: 10px 0;
        background-color: #fff;
        .items {
            background-color: #fff;
            padding: 10px;
            width: 98%;
            margin-left: 1%;
            border: 1px solid #ddd;
            margin-top: 7px;
            border-radius: 4px;
            display: flex;
            flex-direction: column;
            height: 21%;
            &:nth-child(1) {
                height: 28%;
            }
            .itemsTitle {
                display: flex;
                height: 32px;
                align-items: center;
                justify-content: center;
                width: 100%;

                .itemsTitleLeft {
                    display: flex;
                    flex: 1;
                    text-align: left;
                    // color: #3c5dea;
                    img {
                        width: 21px;
                        height: 21px;
                    }
                    label {
                        margin: 0 10px;
                    }
                }
            }
            .itemsContent {
                height: 30px;
                display: flex;
                padding: 10px;
                align-items: center;
                justify-content: center;
                .itemsContentLeftValue {
                    width: 40%;
                    text-align: center;
                    font-size: 20px;
                    font-weight: bold;
                }
                .red {
                    color: red;
                }
                .blue {
                    color: #3751ec;
                }
                .itemsContentRightValue {
                    flex: 1;
                    text-align: right;
                    font-size: 24px;
                    // font-style: italic;
                    // color: #3c5dea;
                    letter-spacing: 1px;
                    font-weight: 400;
                }
                .itemsContentRightValueNoMoney {
                    flex: 1;
                    text-align: right;
                    font-family: 'led';
                    font-size: 40px !important;
                    // font-style: italic;
                    // color: #3c5dea;
                    letter-spacing: 1px;
                    font-weight: 500;
                }
            }
        }
        .floor-left-top-table-center {
            text-align: center;
            div {
                margin-top: 10px;
                margin-bottom: 5px;
            }
        }
        .floor-left-top-table-bottom {
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            .item {
                margin-left: 10px;
                width: calc((100% - 30px) / 2);
                height: 110px;
                position: relative;
                cursor: pointer;
                background-color: #fff;
                margin-bottom: 10px;
                border: 1px solid #e0e0e0;
                border-radius: 4px;
                .item-title {
                    font-size: 14px;
                    background-color: #f5f5f5;
                    height: 30px;
                    line-height: 30px;
                    text-align: center;
                    label {
                        font-size: 12px;
                    }
                }
                .item-value1 {
                    font-size: 16px;
                    color: #000;
                    text-align: center;
                    line-height: 30px;
                }
                .item-value2 {
                    font-size: 13px;
                    line-height: 27px;
                    text-align: left;
                    text-indent: 20px;
                }
                .item-label1 {
                    color: #666;
                    font-size: 13px;
                    text-align: left;
                    text-indent: 20px;
                    line-height: 20px;
                }
                .red {
                    color: red !important;
                }
            }
        }
    }
}
.selectValue {
    display: flex;
    height: 50px;
    background: #fff;
    // margin-top: 5px;
    border-radius: 4px;
    line-height: 50px;
}
.selectValue .value {
    margin-left: 20px;
    font-size: 16px;

    .img {
        display: block;
        float: left;
        margin-top: 4px;
    }
    .title {
        // color: #4e66ed;
        margin-left: 10px;
    }
}
.selectValue .rightValue {
    flex: 1;
    text-align: right;
    margin-right: 20px;
    .btnList {
        .hover {
            border-color: #2680fa !important;
        }
        .btnItem {
            display: inline-block;
            height: 26px;
            width: 60px;
            margin-top: 7px;
            margin-left: 10px;
            line-height: 23px;
            text-align: left;
            border: 1px solid #e0e0e0;
            border-radius: 4px;
            cursor: pointer;
            &:hover {
                border-color: #2680fa;
            }
            &:first-child {
                margin-left: 0 !important;
            }
            svg {
                margin-top: 2px;
                float: left;
                margin-left: 8px;
                margin-right: 3px;
            }
            label {
                font-size: 14px;
            }
        }
    }
}
.selectValue .rightValue span {
    font-size: 16px;
    color: #666;
}
.selectValue .rightValue span b {
    font-size: 16px;
    color: #333;
}
.selectValue .rightValue span label {
    width: 10px;
    display: inline-block;
    height: 10px;
    border-radius: 10px;
    margin-left: 40px;
    margin-right: 5px;
}

.cursor {
    cursor: pointer;
}
.qsHover {
    border: 1px solid #77b4f9;
    border-radius: 5px;
}
</style>
